package com.example.carRental.utils;

import com.example.carRental.exception.CodeEnum;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author
 * @description controller返回结果类（只含了code和message）
 * @date 2022/1/31
 */
@Data
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class R {
    Integer code;
    String message;

    public R(CodeEnum codeEnum) {
        this.code = codeEnum.getCode();
        this.message = codeEnum.getMessage();
    }

    public R(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public static R codeEnum(int code, String message) {
        return new R(code, message);
    }

    public static R success() {
        return new R(CodeEnum.success.code, "成功");
    }

    public static R fail() {
        return new R(CodeEnum.fail.code, "失败");
    }
}
